package com.syyo.gulimall.ware.controller;

//import org.springframework.security.access.prepost.PreAuthorize;

import com.syyo.common.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.syyo.gulimall.ware.domain.req.WareInfoReq;
import com.syyo.gulimall.ware.service.WareInfoService;
import com.syyo.common.domain.ResultVo;


/**
 * 仓库信息
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 10:06:54
 */
@RestController
@RequestMapping("/ware/wareinfo")
public class WareInfoController {

    @Autowired
    private WareInfoService wareInfoService;

    /**
     * 新增
     */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:wareinfo:add')")
    public ResultVo add(@RequestBody WareInfoReq req) {
        return ResultUtils.ok(wareInfoService.add(req));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:wareinfo:del')")
    public ResultVo del(@PathVariable("id") Integer id) {
        return ResultUtils.ok(wareInfoService.del(id));
    }

    /**
     * 修改
     */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:wareinfo:edit')")
    public ResultVo edit(@RequestBody WareInfoReq req) {
        return ResultUtils.ok(wareInfoService.edit(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return ResultUtils.ok(wareInfoService.findOne(id));
    }

    /**
     * 列表
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             WareInfoReq req) {
        return ResultUtils.ok(wareInfoService.findPage(pageNum, pageSize, req));
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public ResultVo findAll(WareInfoReq req) {
        return ResultUtils.ok(wareInfoService.findAll(req));
    }

    /**
     * 获取运费信息
     */
    @GetMapping("/fare")
    public ResultVo getFare(@RequestParam("addrId") Long addrId) {
        return ResultUtils.ok(wareInfoService.getFare(addrId));
    }
}
